<template >
  <div class="box-x">
    <div class="box-a">
      <div class="nav clearfix">
        <div class="icon">
          <img src="/img/logo_mi.png" alt="">
        </div>
        <div class="title">
           <h2>我的购物车</h2>
          <p>温馨提示：产品是否购买成功，以最终下单为准哦，请尽快结算</p> 
        </div>
        <div class="info clearfix">
          <span class="p1" @mouseenter="move(-1)" @mouseleave="move(1)">
           <router-link to="#" :style="mou"
           >用户账号
             <img v-if="show" src="@/assets/xia.png" alt="" style="margin-left:5px;" >
          <img v-else src="@/assets/xiaa.png" alt="" style="margin-left:5px;width:16px"></router-link> 
          <ul class="move">
            <li><router-link to="#">
              个人中心
              </router-link>
              </li>
            <li>
             <router-link to="#">
              晒单评价
              </router-link>
              </li>
            <li>
               <router-link to="#">
              我的喜欢
              </router-link>
              </li>
            <li>
              <router-link to="#">
              小米账号
              </router-link>
              </li>
            <li>
               <router-link to="#">
              退出登录
              </router-link>
              </li>
          </ul>
          </span>
          <p  id="border" ></p> 
          <span class="p2"><router-link to="#">我的订单</router-link></span>
        </div>
      </div>
    </div>
    <div class="box-b clearfix" >
      <div class="checkbox">
        <div class="box-ba">
        <input type="checkbox" id="box-b">
        <label for="box-b" @click="label" :class="[lab?'label':'']">✔</label>全选</div>
        </div>
      <div class="image">图片</div>
      <div class="pname">商品名称</div>
      <div class="price">单价</div>
      <div class="count">数量</div>
      <div class="sub">小计</div>
      <div class="err">操作</div>
    </div>
    <div class="box-c clearfix"  v-for="(item,index) in shopping" :key="index">
      <div class="checked">
        <div class="che-a">
          <input type="checkbox" id="che-a">
          <label  for="che-a" :class="[lab?'label':'']" @click="xuan"  >✔</label>
        </div>
      </div>
      <div class="img"><img :src="item.image" alt=""></div>
      <div class="aname">{{item.sname}}</div>
      <div class="pri">{{item.price}}元</div>
      <div class="btn">  
        <div class="btna" >
  <div class="btns" @click="minus(index)" ><img src="@/assets/jian.png" alt=""></div>
  <input type="text" maxlength="2" v-model="item.number" ref="input">
  <div class="btns1" @click="add(index)" >
    <img src="@/assets/jia.png" alt=""></div>
        </div>
        </div>
      <div class="num">{{item.price*Number(item.number)}}元</div>
      <div class="xz"><span @click="cha(index)"><img src="@/assets/cha.png" alt=""></span></div>
    </div>
    
    <div class="box-d"></div>
    <div class="tc" :style="over">
       <div class="user" >
        <div class="content" ref="inner">
          输入的数量只能是数字！ 
        </div>
          <span @click="ov" ><img src="@/assets/cha.png" /></span>
        <div class="button">
          <button @click="ov">确定</button>
        </div>
       </div>     
    </div>
  </div>
</template>
<style scoped  lang="scss">
//弹窗
.tc{
 width: 100%;
 height: 100%;
 position: fixed;
 top: 0;
 left: 0;
 background-color: rgba(0,0,0,0.2);
  .user{
    width: 480px;
    height: 260px;
     position: absolute;
    top: 50%;
    left: 50%;
    margin-left:-240px;
   margin-top:-130px;
   box-shadow: 0 1px 3px;
    span{
       padding: 0;
       margin: 0;
       width: 22px;
       height: 22px;
       border-radius: 50%;
       position: absolute;
       top: 20px;
       right: 20px;
        cursor: pointer;
      img{
      display: block;
      margin-left:6px ;
      margin-top: 5px;
       width: 12px;
      }
     }
      span:hover{
    background-color: rgba(241, 13, 13, 0.5); 
    }
   .content{
    width: 100%;
    height: 180px;
    background-color: #fff;
    font-size: 26px;
    text-align: center;
    line-height: 180px;
    color: black;
     border-bottom:1px solid #757575 ;
   }
   .button{
    width: 100%;
    height: 80px;
    background-color: #f5f5f5;
    text-align: center;
    line-height: 80px;
    button{
      width: 160px;
      height: 40px;
    background-color: #ff6700;
    border: 0;
    color: white;
    }
   }
}
}
/* 背景 */
.box-x{
 background-color:#f9f9f9; 

}
/* 清除浮动 */
.clearfix:after{
  content: "";
  display: block;
  height: 0;
  clear: both;
  visibility: hidden;
}
 .box-a{
      background-color: #Ffff;
   width: 100%;
    height: 100PX;
    border-bottom: 2px solid #ff6700;
 }
 .box-a>.nav{
   width: 1200px;
  
   height: 100%;
   margin: 0 auto;
 }
 /* 图片 */
  .box-a>.nav>.icon{
  float: left;
  align-items: center;
    width: 48px;
    margin-top: 26px;
    margin-right: 40px;
  }
 .box-a>.nav>.icon>img{
 width: 100%;

 }
 /* 标题 */
 .box-a>.nav>.title{
   margin-top: 36px;
   float: left;
   display: flex;
   justify-content: center;
 }
  .box-a>.nav>.title>h2{
    color: #424242;
    font-size: 28px;
  }
  .box-a>.nav>.title>p{
     margin-top: 12px;
     margin-left: 10px;
     color: #757575;
     font-size: 10px;
  }
 /* 用户信息 */
  .box-a>.nav>.info{
    float: right;
    display: flex;
    justify-content: right;
    position: relative;
  }
  .box-a>.nav>.info>span,span,#border{
     margin-top: 50px;
     margin-left: 17px;
       color: #757575;
     font-size: 10px;
     display: inline-block; 
  }
   .box-a>.nav>.info>.p1:hover{
     cursor: pointer;
   }
    .box-a>.nav>.info>.p2:hover{
       color: #ff6700 ;
     cursor: pointer;
    }
  .box-a>.nav>.info>#border{
     height: 17px;
    border-right: 1px solid #757575 ;
    margin-left: 10px;
  }
 /* 下拉列表 */
  .box-a>.nav>.info .move{
  display: none;
  height:140px;
    background-color: #f9f9f9;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    width: 100px;
    position: absolute;
    z-index: 1;
   padding-top: 5px;
  }
 .box-a>.nav>.info .move>li{
   margin-top: 14px;
 }
  .box-a>.nav>.info .move>li:hover{
    background-color: #f1f1f1
  }
  .box-a>.nav>.info>.p1:hover .move{
    display:block; 
     
  }
  .box-a>.nav>.info>.p1>a{
    color: #757575;
  }
  .box-a>.nav>.info>.p1{
    width: 90px;
  }
   .box-a>.nav>.info>.p1>a:hover{
     color:#ff6700 ;
   }
   .box-a>.nav>.info>.p2>a{
      color: #757575
   }
    .box-a>.nav>.info>.p2>a:hover{
      color: #ff6700;
    }
   /* 下拉菜单 的颜色*/
     .box-a>.nav>.info>.p1>.move>li>a{
        color: #757575;
       font-size: 10px; 
     }
       .box-a>.nav>.info>.p1>.move>li>a:hover{
         color:#ff6700 ;
       }
       /* 商品列表 */
        .box-x>.box-b{
          width: 1200px;
            margin:0 auto;
            margin-top: 38px;
            background-color: #fff;
            border-bottom: 1px solid rgba(133,133,133,0.5);
            position: relative;
           font-size: 14px;
           color: #424242;
        }
       .box-x>.box-b>div{
         float: left;
          height: 70px;
          text-align: center;
          line-height: 70px;
       }
       /* 选择*/
        .box-x>.box-b>.checkbox{
          width: 100px;
          position: relative;
          input{
            margin-right: 15px;
          }
          .box-ba>label{
            width: 18px;
            height: 18px;
             border: 1px solid #e0e0e0;
             background-color: #fff;
            display: inline-block;
            position: absolute;
            top: 25px;
            left: 20px;
                font-size: 17px;
              text-align: center;
              line-height: 18px;
              color: #fff;
          }
          .box-ba>label:hover{
            color:#e0e0e0; 
          }
        
        }
          .label{
             background-color:#ff6700 !important;
              color: #fff !important
          } 
        /* 图片 */
          .box-x>.box-b>.image{
            width: 120px;
          }
          
          /* 商品名称 */
           .box-x>.box-b>.pname{
             width: 370px;
              text-align: left;
            margin-left: 20px;
            
           }
          /* 单价 */
            .box-x>.box-b>.price{
              width: 150px;
            }
            /* 数量 */
              .box-x>.box-b>.count{
                width: 150px;
              }
              /* 小计 */
                .box-x>.box-b>.sub{
                  width: 140px;
                  position: absolute;
                  left: 890px;
                margin-right: 80px;
                  text-align: right;
                }
                /* 操作 */
                  .box-x>.box-b>.err{
                    width: 80px;
                    margin-right: 30px;
                    position: absolute;
                    left: 1090px;
                  }
      /* 商品列表  for循环遍历的 */
      .box-c{
        width: 1200px;
        margin: 0 auto;
         text-align: center;
         line-height:110px ;
         border-bottom: 1px solid rgba(133,133,133,0.5);
        background-color: #fff;
        font-size: 18px;
        color: #424242;
        div{
          float: left;
           height: 110px;
        }
        // 选择
        .checked{
          width: 100px;
          position: relative;
           input{
           margin-left: 25px;
          }
          .che-a>label{
            width: 18px;
            height: 18px;
             border: 1px solid #e0e0e0;
             background-color: #fff;
            display: inline-block;
            position: absolute;
            top: 45px;
            left: 20px;
                font-size: 17px;
              text-align: center;
              line-height: 18px;
              color: #fff;
          }
          .che-a>label:hover{
            color:#e0e0e0; 
          }
         
        }
         //图片
         .img{
           width: 120px;
           img{
             width: 80px;
             height: 80px;
             padding-top: 10px;
           }
         }
         //名字
         .aname{
           width: 370px;
           text-align: left;
           margin-left: 20px;
           color: #424242;
           font-size: 18px;
         }
         //价格
         .pri{
           width: 150px;
         }
         //数量
         .btn{
          width: 150px;
             .btna{
            width: 148px;
            height: 40px;
             margin-top: 35px;
             position: relative;
             border: 1px solid  rgba(133,133,133,0.5);
              .btns:hover{
               background-color:rgba(133,133,133,0.5);
                cursor: pointer;
            }
           .btns{
             position: absolute;
             width: 38px;
              height: 40px;
              img{
            width: 12px;
            display: block;
            margin: auto;
           margin-top: 15px;
          }
           }
           .btns1:hover{
            background-color:rgba(133,133,133,0.5);
            cursor: pointer;
            }
           .btns1{
          position: absolute;
           display: block;
           width: 38px;
           height: 40px;
          right: 0;
          img{
            width: 12px;
            display: block;
            margin: auto;
              margin-top: 15px;
          }
           }
            input{
              position: absolute;
              margin: auto;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            width: 72px;
            height: 38px;
            border: 0;
            color: #424242;
            font-size: 16px;
            text-align: center;
            }
          }
         }
         //小计
         .num{
           width: 120px;
          padding-right: 80px;
           color: #ff6700;
           font-size: 16px;
           text-align: right;
         }
         //计算
         .xz{
           width: 80px;
           margin-left: -17px;
           cursor: pointer;
           margin-right: 20px;
           span{
             width: 22px;
             height: 22px;
             border-radius: 50%;
             position: relative;
             margin-left: -8px;
              margin-top: 40px;
             
             img{
               position: absolute;
               width: 12px;
               left: 5px;
               top: 5px;
             }
           }
           span:hover{
        background-color: rgba(241, 13, 13, 0.5);
        
           }
         }
      }
</style>
<script>
export default {
    data() {
      return {
        show:true,
        mou:"color:#757575",
        number:1,
        lab:false,
        laba:false,
        over:'display:none',
        shopping:[//商品列表
       {image:'/img/pm.jpg',sname:'饮水器',price:699,number:1},
       {image:'/img/pm.jpg',sname:'饮水器',price:799,number:1},
       {image:'/img/pm.jpg',sname:'饮水器',price:899,number:1},
       {image:'/img/pm.jpg',sname:'饮水器',price:999,number:1},
     
     ]
      }
    },
    methods:{
      //箭头的颜色变化
      move(event){
       
        if(event<0){
           this.show=false;
           this.mou="color:#ff6700"
        }else{
          this.show=true;
            this.mou="color:#757575"
        }
      },
      label(){
     
        if(this.lab==false){
          this.lab=true;
        }else{
          this.lab=false;
        }
      },
      xuan(){
          if(this.laba==false){
          this.laba=true;
        }else{
          this.laba=false;
        }
      },
      //input
      minus(index){
      //  console.log(index);
      //  console.log(this.shopping[index].number);
        if(this.shopping[index].number>1){
            // this.number--
      
           this.shopping[index].number--
              // this.number--
      
        }else{
           setTimeout(()=>{
             this.over=''
             this.$refs.inner.innerHTML="修改数量不能小于0";
              this.$refs.input.blur
          },50)
        }
      
      },
      add(index){ 
        //  console.log(index);
        //  console.log(index);
        // console.log(this.shopping[index].number);
        if(this.shopping[index].number<20){
         this.shopping[index].number++
        // this.number++
           
        }else{
          setTimeout(()=>{
           this.over=""
         
           this.$refs.inner.innerHTML="商品加入购物车数量超过限购数";
            this.$refs.input.blur
           },50)
        }
      },
      //弹窗
      ov(){
       this.over="display:none";
      },
      //叉掉
      cha(e){
    
         this.shopping.splice(e,1)
        
      },
      //返回shopping中的属性和属性值
     
      
    },
       //监视函数
   watch:{
     shopping:{
       handler:function(number){
      
          for (let index = 0; index < number.length; index++) {
                // number.index
                // console.log(number.index);
            if(isNaN(number[index].number)){
         
           this.over=""
          this.$refs.inner.innerHTML="输入的数量只能是数字！"
         this.shopping[index].number=1;
            this.$refs.input.blur
    
          return 
          
        }
   }
        },
         deep:true
     },
   
   },

}
         
        
        
   
</script>